<template>
	<view>

		<swiperTabHead :tabBars="tabBars" :tabIndex="tabIndex" @tabtap="tabtap">
		</swiperTabHead>

		<view class="uni-tab-bar">
			<swiper :style="{height:swiperHeight+'px'}" :current="tabIndex" @change="swiperChange">
				<swiper-item v-for="(items, index) in newlist" :key="index">
					<scroll-view scroll-y class="list" @scrolltolower="loadmore(index)">
						<template v-if="items.list.length > 0">
							<!-- 图文列表 -->
							<block v-for="(item, index1) in items.list" :key="index1">
								<indexList :item="item" :index="index1"></indexList>
							</block>
							<!-- 上拉加载 -->
							<loadMore :loadtext="items.loadtext"></loadMore>
						</template>
						<template v-else>
							<!-- 无内容 -->
							<noThing></noThing>
						</template>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>

	</view>
</template>

<script>
	import indexList from '../../components/index/index-list.vue';
	import swiperTabHead from '../../components/common/swiper-tab-head.vue';
	import loadMore from '../../components/common/load-more.vue';
	import noThing from '../../components/common/no-thing.vue';

	export default {
		components: {
			indexList,
			swiperTabHead,
			loadMore,
			noThing
		},
		data() {
			return {
				swiperHeight: 500,
				tabBars: [{
						name: "关注",
						id: "guanzhu"
					},
					{
						name: "推荐",
						id: "tuijian"
					},
					{
						name: "体育",
						id: "tiyu"
					},
					{
						name: "热点",
						id: "redian"
					},
					{
						name: "财经",
						id: "caijing"
					},
					{
						name: "娱乐",
						id: "yule"
					},
				],
				tabIndex: 0,
				newlist: [{
						loadtext: "上拉加载更多",
						list: [{
								userpic: "../../static/demo/userpic/1.jpg",
								username: "昵称",
								isguanzhu: false,
								title: "我是标题1",
								type: "img", //img:图文 video: 视频
								titlepic: "../../static/demo/datapic/11.jpg",
								infoNum: {
									index: 1, //0 - 没有操作, 1 - 顶, 2 - 踩
									dingNum: 11,
									caiNum: 12,
								},
								commentNum: 12,
								shareNum: 123
							},
							{
								userpic: "../../static/demo/userpic/1.jpg",
								username: "昵称",
								isguanzhu: true,
								title: "我是标题2",
								type: "video", //img:图文 video: 视频
								titlepic: "../../static/demo/datapic/11.jpg",
								playNum: "20w",
								long: "2:47",
								infoNum: {
									index: 2, //0 - 没有操作, 1 - 顶, 2 - 踩
									dingNum: 1,
									caiNum: 14,
								},
								commentNum: 12,
								shareNum: 123
							}
						]
					},
					{
						loadtext: "上拉加载更多",
						list: [{
								userpic: "../../static/demo/userpic/2.jpg",
								username: "昵称",
								isguanzhu: false,
								title: "我是标题3",
								type: "img", //img:图文 video: 视频
								titlepic: "../../static/demo/datapic/12.jpg",
								infoNum: {
									index: 1, //0 - 没有操作, 1 - 顶, 2 - 踩
									dingNum: 11,
									caiNum: 12,
								},
								commentNum: 12,
								shareNum: 123
							},
							{
								userpic: "../../static/demo/userpic/2.jpg",
								username: "昵称",
								isguanzhu: true,
								title: "我是标题4",
								type: "video", //img:图文 video: 视频
								titlepic: "../../static/demo/datapic/11.jpg",
								playNum: "20w",
								long: "2:47",
								infoNum: {
									index: 2, //0 - 没有操作, 1 - 顶, 2 - 踩
									dingNum: 1,
									caiNum: 14,
								},
								commentNum: 12,
								shareNum: 123
							}
						]
					},
					{
						loadtext: "上拉加载更多",
						list: []
					},
					{
						loadtext: "上拉加载更多",
						list: []
					},
					{
						loadtext: "上拉加载更多",
						list: []
					},
					{
						loadtext: "上拉加载更多",
						list: []
					}

				]
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					let height = res.windowHeight - uni.upx2px(100);
					// console.log(height);
					this.swiperHeight = height;
				}
			})
		},
		//监听搜索框点击事件
		onNavigationBarSearchInputClicked() {
			uni.navigateTo({
				url:"../search/search"
			})
		},
		onNavigationBarButtonTap(e) {
			// console.log(JSON.stringify(e.index));
			switch (e.index){
				case 0:
				break;
				case 1:
				uni.navigateTo({
					url:"../add-input/add-input"
				})
				break;
			}
		},
		methods: {
			// 上拉加载
			loadmore(index){
				if(this.newlist[index].loadtext != "上拉加载更多") {return;}
				this.newlist[index].loadtext = "加载中";
				setTimeout(()=>{
					//获取完成
					let obj = {
								userpic: "../../static/demo/userpic/2.jpg",
								username: "昵称",
								isguanzhu: false,
								title: "我是标题",
								type: "img", //img:图文 video: 视频
								titlepic: "../../static/demo/datapic/12.jpg",
								infoNum: {
									index: 1, //0 - 没有操作, 1 - 顶, 2 - 踩
									dingNum: 11,
									caiNum: 12,
								},
								commentNum: 12,
								shareNum: 123
							};
					this.newlist[index].list.push(obj);
					this.newlist[index].loadtext = "上拉加载更多";
				},1000)
				// this.newlist[index].loadtext = "上拉加载更多";
				// this.newlist[index].loadtext = "加载中";
				// this.newlist[index].loadtext = "没有更多数据了";
			},
			//tabbar点击事件
			tabtap(index) {
				this.tabIndex = index;
			},
			//swiper滑动事件
			swiperChange(e) {
				// console.log(JSON.stringify(e.detail));
				this.tabIndex = e.detail.current;
			}
		}
	}
</script>

<style>
	
</style>
